﻿using System;
using System.Collections.Generic;
using Rio.Framework.Pages.AppCode.Enums;
using NetBay.Core.BusinessEntities;
using Rio.Framework.Pages.Context;
using System.ComponentModel;

namespace Rio.Framework.Pages.Controls.BaseClass.Navigation
{
    /// <summary>
    /// Base class of RIO Toolbar components
    /// </summary>
    public class NavigationBase : ControlBase, INotifyPropertyChanged
    {
        #region Attributes

        #endregion

        #region Properties

        public ConsultationModeType ConsultationMode { get; set; }
        //protected int SelectedDocumentIndex { get; set; }
        //protected int TotalOfDocument { get; set; }
        public AppDisplayMode AppDisplayMode { get; set; }
        public AppViewMode ViewMode { get; set; }
        public Organization Organization { get; set; }
        public FolderType FolderType { get; set; }
        public bool ScanImportIsEnabled { get; set; }
        public bool IsVersioningEnabled { get; set; }
        public int SelectedDocumentCount { get; set; }

        #endregion

        #region Enums

        #region Workflow Mode

        protected List<DocumentRibbonBarMenuItems> workflowModeEnum = new List<DocumentRibbonBarMenuItems>()
                                                                          {
                                                                              DocumentRibbonBarMenuItems.SearchPrevious,
                                                                              DocumentRibbonBarMenuItems.SearchNext,
                                                                              DocumentRibbonBarMenuItems.FitHeight,
                                                                              DocumentRibbonBarMenuItems.FitWidth,
                                                                              DocumentRibbonBarMenuItems.ZoomIn,
                                                                              DocumentRibbonBarMenuItems.ZoomOut,
                                                                              DocumentRibbonBarMenuItems.ZoomGroup,
                                                                              DocumentRibbonBarMenuItems.RotateLeft,
                                                                              DocumentRibbonBarMenuItems.RotateRight,
                                                                              DocumentRibbonBarMenuItems.DocumentMode,
                                                                              DocumentRibbonBarMenuItems.ThumbnailsMode,
                                                                              DocumentRibbonBarMenuItems.ListMode,
                                                                              DocumentRibbonBarMenuItems.SelectAll,
                                                                              DocumentRibbonBarMenuItems.SelectNone,
                                                                              DocumentRibbonBarMenuItems.SendEmail,
                                                                              DocumentRibbonBarMenuItems.Download,
                                                                              DocumentRibbonBarMenuItems.Ventilate,
                                                                              DocumentRibbonBarMenuItems.Print,
                                                                              DocumentRibbonBarMenuItems.DocumentPrint,
                                                                              DocumentRibbonBarMenuItems.Cut,
                                                                              DocumentRibbonBarMenuItems.Copy,
                                                                              DocumentRibbonBarMenuItems.Paste,
                                                                              DocumentRibbonBarMenuItems.FolderLink,
                                                                          };

        #endregion

        #region Trash Mode

        protected List<DocumentRibbonBarMenuItems> TrashModeEnum = new List<DocumentRibbonBarMenuItems>()
                                                                    {
                                                                        DocumentRibbonBarMenuItems.ZoomIn,
                                                                        DocumentRibbonBarMenuItems.ZoomOut,
                                                                        DocumentRibbonBarMenuItems.ZoomGroup,
                                                                        DocumentRibbonBarMenuItems.RotateLeft,
                                                                        DocumentRibbonBarMenuItems.RotateRight,
                                                                        DocumentRibbonBarMenuItems.DocumentMode,
                                                                        DocumentRibbonBarMenuItems.ThumbnailsMode,
                                                                        DocumentRibbonBarMenuItems.ListMode,
                                                                        DocumentRibbonBarMenuItems.Delete,
                                                                        DocumentRibbonBarMenuItems.SelectAll,
                                                                        DocumentRibbonBarMenuItems.SelectNone,
                                                                        DocumentRibbonBarMenuItems.FolderLink,
                                                                    };

        #endregion

        #region Old Version Mode

        protected List<DocumentRibbonBarMenuItems> OldVersionModeEnum = new List<DocumentRibbonBarMenuItems>()
                                                                    {
                                                                        DocumentRibbonBarMenuItems.SearchPrevious,
                                                                        DocumentRibbonBarMenuItems.SearchNext,
                                                                        DocumentRibbonBarMenuItems.FitHeight,
                                                                        DocumentRibbonBarMenuItems.FitWidth,
                                                                        DocumentRibbonBarMenuItems.ZoomIn,
                                                                        DocumentRibbonBarMenuItems.ZoomOut,
                                                                        DocumentRibbonBarMenuItems.ZoomGroup,
                                                                        DocumentRibbonBarMenuItems.RotateLeft,
                                                                        DocumentRibbonBarMenuItems.RotateRight,
                                                                        DocumentRibbonBarMenuItems.DocumentMode,
                                                                        DocumentRibbonBarMenuItems.SelectAll,
                                                                        DocumentRibbonBarMenuItems.SelectNone,
                                                                        DocumentRibbonBarMenuItems.Print,
                                                                        DocumentRibbonBarMenuItems.DocumentPrint,
                                                                        DocumentRibbonBarMenuItems.Download,
                                                                        DocumentRibbonBarMenuItems.FolderLink,
                                                                    };

        #endregion

        #region Viewer mode declarations
        protected List<DocumentRibbonBarMenuItems> SingleModeAvailables = new List<DocumentRibbonBarMenuItems>()
                                                                    {
                                                                        #region Display mode
                                                                            DocumentRibbonBarMenuItems.Scan,
                                                                            DocumentRibbonBarMenuItems.Import,
                                                                        #endregion
                                                                        #region Display mode
                                                                            DocumentRibbonBarMenuItems.ThumbnailsMode,
                                                                            DocumentRibbonBarMenuItems.ListMode,
                                                                        #endregion
                                                                        #region Selection
                                                                        #endregion
                                                                        #region Fitting
                                                                            DocumentRibbonBarMenuItems.FitHeight,
                                                                            DocumentRibbonBarMenuItems.FitWidth,
                                                                        #endregion
                                                                        #region Zoom
                                                                            DocumentRibbonBarMenuItems.ZoomGroup,
                                                                            DocumentRibbonBarMenuItems.ZoomIn,
                                                                            DocumentRibbonBarMenuItems.ZoomOut,
                                                                        #endregion
                                                                        #region Rotate
                                                                            DocumentRibbonBarMenuItems.RotateGroup,
                                                                            DocumentRibbonBarMenuItems.RotateLeft,
                                                                            DocumentRibbonBarMenuItems.RotateRight,
                                                                            DocumentRibbonBarMenuItems.SaveModifications,
                                                                        #endregion
                                                                        #region Search
                                                                            DocumentRibbonBarMenuItems.SearchPrevious,
                                                                            DocumentRibbonBarMenuItems.SearchNext,
                                                                        #endregion
                                                                        #region Actions
                                                                            DocumentRibbonBarMenuItems.ActionGroup,
                                                                            DocumentRibbonBarMenuItems.Delete,
                                                                            DocumentRibbonBarMenuItems.MergePDF,
                                                                            DocumentRibbonBarMenuItems.Download,
                                                                            DocumentRibbonBarMenuItems.SendEmail,
                                                                            DocumentRibbonBarMenuItems.Print,
                                                                            DocumentRibbonBarMenuItems.DocumentPrint,
                                                                            DocumentRibbonBarMenuItems.AddDocument,
                                                                            DocumentRibbonBarMenuItems.Split2,
                                                                            DocumentRibbonBarMenuItems.Split3,
                                                                            DocumentRibbonBarMenuItems.SplitPDF,
                                                                            DocumentRibbonBarMenuItems.FolderLink,
                                                                        #endregion
                                                                        #region Edit
                                                                            DocumentRibbonBarMenuItems.EditGroup,
                                                                            DocumentRibbonBarMenuItems.Cut,
                                                                            DocumentRibbonBarMenuItems.Copy,
                                                                            DocumentRibbonBarMenuItems.Paste,
                                                                            DocumentRibbonBarMenuItems.CheckIn,
                                                                            DocumentRibbonBarMenuItems.CheckOut,

                                                                        #endregion
                                                                        #region Workflow
                                                                            DocumentRibbonBarMenuItems.WorkflowGroup,
                                                                            DocumentRibbonBarMenuItems.Ventilate,
                                                                        #endregion
                                                                        #region Outlook
                                                                            DocumentRibbonBarMenuItems.PlugginGroup,
                                                                            DocumentRibbonBarMenuItems.OpenDirectory,
                                                                            DocumentRibbonBarMenuItems.ReturnDirectory,
                                                                        #endregion
                                                                    };

        protected List<DocumentRibbonBarMenuItems> ThumbnailModeAvailables = new List<DocumentRibbonBarMenuItems>()
                                                                                 {
                                                                                     #region Display mode
                                                                                     DocumentRibbonBarMenuItems.Scan,
                                                                                     DocumentRibbonBarMenuItems.Import,

                                                                                     #endregion
                                                                                     #region Display mode
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         DocumentMode,
                                                                                     DocumentRibbonBarMenuItems.ListMode,

                                                                                     #endregion
                                                                                     #region Selection
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         SelectAll,
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         SelectNone,

                                                                                     #endregion
                                                                                     #region Rotate
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         RotateGroup,
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         RotateLeft,
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         RotateRight,
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         SaveModifications,

                                                                                     #endregion
                                                                                     #region Actions
                                                                                     DocumentRibbonBarMenuItems.ActionGroup,
                                                                                     DocumentRibbonBarMenuItems.Delete,
                                                                                     DocumentRibbonBarMenuItems.MergePDF,
                                                                                     DocumentRibbonBarMenuItems.SplitPDF,
                                                                                     DocumentRibbonBarMenuItems.Download,
                                                                                     DocumentRibbonBarMenuItems.SendEmail,
                                                                                     DocumentRibbonBarMenuItems.Print,
                                                                                     DocumentRibbonBarMenuItems.AddDocument,
                                                                                     DocumentRibbonBarMenuItems.Split2,
                                                                                     DocumentRibbonBarMenuItems.Split3,
                                                                                     DocumentRibbonBarMenuItems.FolderLink,
                                                                                     #endregion
                                                                                     #region Edit
                                                                                     DocumentRibbonBarMenuItems.EditGroup,
                                                                                     DocumentRibbonBarMenuItems.Cut,
                                                                                     DocumentRibbonBarMenuItems.Copy,
                                                                                     DocumentRibbonBarMenuItems.Paste,
                                                                                     DocumentRibbonBarMenuItems.CheckIn,
                                                                                     DocumentRibbonBarMenuItems.CheckOut,

                                                                                     #endregion
                                                                                     #region Workflow
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         WorkflowGroup,
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         Ventilate,

                                                                                     #endregion
                                                                                     #region Outlook
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         PlugginGroup,
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         OpenDirectory,
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         ReturnDirectory,

                                                                                     #endregion
                                                                                 };

        protected List<DocumentRibbonBarMenuItems> ListModeAvailables = new List<DocumentRibbonBarMenuItems>()
                                                                            {
                                                                                #region Display mode
                                                                                DocumentRibbonBarMenuItems.Scan,
                                                                                DocumentRibbonBarMenuItems.Import,

                                                                                #endregion
                                                                                #region Display mode
                                                                                DocumentRibbonBarMenuItems.DocumentMode,
                                                                                DocumentRibbonBarMenuItems.
                                                                                    ThumbnailsMode,

                                                                                #endregion
                                                                                #region Selection
                                                                                DocumentRibbonBarMenuItems.SelectAll,
                                                                                DocumentRibbonBarMenuItems.SelectNone,

                                                                                #endregion
                                                                                #region Actions
                                                                                DocumentRibbonBarMenuItems.ActionGroup,
                                                                                DocumentRibbonBarMenuItems.Delete,
                                                                                DocumentRibbonBarMenuItems.MergePDF,
                                                                                DocumentRibbonBarMenuItems.Download,
                                                                                DocumentRibbonBarMenuItems.SendEmail,
                                                                                DocumentRibbonBarMenuItems.Print,
                                                                                DocumentRibbonBarMenuItems.AddDocument,
                                                                                DocumentRibbonBarMenuItems.SplitPDF,
                                                                                DocumentRibbonBarMenuItems.Split2,
                                                                                     DocumentRibbonBarMenuItems.Split3,
                                                                                     DocumentRibbonBarMenuItems.FolderLink,
                                                                                #endregion
                                                                                #region Edit
                                                                                DocumentRibbonBarMenuItems.EditGroup,
                                                                                DocumentRibbonBarMenuItems.Cut,
                                                                                DocumentRibbonBarMenuItems.Copy,
                                                                                DocumentRibbonBarMenuItems.Paste,
                                                                                DocumentRibbonBarMenuItems.CheckIn,
                                                                                DocumentRibbonBarMenuItems.CheckOut,

                                                                                #endregion
                                                                                #region Workflow
                                                                                DocumentRibbonBarMenuItems.WorkflowGroup,
                                                                                DocumentRibbonBarMenuItems.Ventilate,

                                                                                #endregion
                                                                                #region Outlook
                                                                                DocumentRibbonBarMenuItems.PlugginGroup,
                                                                                DocumentRibbonBarMenuItems.OpenDirectory,
                                                                                DocumentRibbonBarMenuItems.
                                                                                    ReturnDirectory,

                                                                                #endregion
                                                                                #region Rotate
                                                                                     DocumentRibbonBarMenuItems.
                                                                                         SaveModifications,

                                                                                     #endregion
                                                                            };

        protected List<DocumentRibbonBarMenuItems> ImportModeExclude = new List<DocumentRibbonBarMenuItems>()
                                                                           {
                                                                               #region Actions
                                                                               DocumentRibbonBarMenuItems.OpenDirectory,
                                                                               DocumentRibbonBarMenuItems.
                                                                                   ReturnDirectory,
                                                                               DocumentRibbonBarMenuItems.
                                                                                   SaveModifications,
                                                                               DocumentRibbonBarMenuItems.Download,
                                                                               DocumentRibbonBarMenuItems.SendEmail,
                                                                               DocumentRibbonBarMenuItems.Print,
                                                                               DocumentRibbonBarMenuItems.DocumentPrint,
                                                                               DocumentRibbonBarMenuItems.AddDocument,
                                                                               DocumentRibbonBarMenuItems.SearchNext,
                                                                               DocumentRibbonBarMenuItems.SearchPrevious,
                                                                               DocumentRibbonBarMenuItems.AddVersion,
                                                                               DocumentRibbonBarMenuItems.
                                                                                   MakeToMajorVersion,

                                                                               #endregion
                                                                               #region Edit
                                                                               DocumentRibbonBarMenuItems.EditGroup,
                                                                               DocumentRibbonBarMenuItems.Cut,
                                                                               DocumentRibbonBarMenuItems.Copy,
                                                                               DocumentRibbonBarMenuItems.Paste,
                                                                               DocumentRibbonBarMenuItems.FolderLink,

                                                                               #endregion
                                                                               #region Workflow
                                                                               DocumentRibbonBarMenuItems.WorkflowGroup,
                                                                               DocumentRibbonBarMenuItems.Ventilate,

                                                                               #endregion
                                                                           };

        protected List<DocumentRibbonBarMenuItems> ImportModeDirectoryExclude = new List<DocumentRibbonBarMenuItems>()
                                                                                    {
                                                                                        #region Actions
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            ReturnDirectory,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            MergePDF,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            Download,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            SendEmail,
                                                                                        DocumentRibbonBarMenuItems.Print,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            DocumentPrint,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            AddDocument,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            SearchNext,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            SearchPrevious,

                                                                                        #endregion
                                                                                        #region Edit
                                                                                        DocumentRibbonBarMenuItems.EditGroup,
                                                                                        DocumentRibbonBarMenuItems.Cut,
                                                                                        DocumentRibbonBarMenuItems.Copy,
                                                                                        DocumentRibbonBarMenuItems.Paste,
                                                                                        DocumentRibbonBarMenuItems.FolderLink,
                                                                                        #endregion
                                                                                        #region Workflow
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            WorkflowGroup,
                                                                                        DocumentRibbonBarMenuItems.
                                                                                            Ventilate,

                                                                                        #endregion
                                                                                    };

        protected List<DocumentRibbonBarMenuItems> SearchModeExclude = new List<DocumentRibbonBarMenuItems>()
                                                                           {
                                                                               #region Display mode
                                                                               DocumentRibbonBarMenuItems.Scan,
                                                                               DocumentRibbonBarMenuItems.Import,

                                                                               #endregion
                                                                               #region Rotate
                                                                               DocumentRibbonBarMenuItems.
                                                                                   SaveModifications,

                                                                               #endregion
                                                                               #region Actions
                                                                               DocumentRibbonBarMenuItems.MergePDF,
                                                                               DocumentRibbonBarMenuItems.SplitPDF,
                                                                               DocumentRibbonBarMenuItems.Split2,
                                                                               DocumentRibbonBarMenuItems.Split3,

                                                                               #endregion
                                                                               #region Outlook
                                                                               DocumentRibbonBarMenuItems.PlugginGroup,
                                                                               DocumentRibbonBarMenuItems.OpenDirectory,
                                                                               DocumentRibbonBarMenuItems.
                                                                                   ReturnDirectory,

                                                                               #endregion
                                                                           };

        protected List<DocumentRibbonBarMenuItems> FlowModeExclude = new List<DocumentRibbonBarMenuItems>()
                                                                         {
                                                                             #region Display mode
                                                                             DocumentRibbonBarMenuItems.Scan,
                                                                             DocumentRibbonBarMenuItems.Import,

                                                                             #endregion
                                                                             #region Rotate
                                                                             DocumentRibbonBarMenuItems.
                                                                                 SaveModifications,

                                                                             #endregion
                                                                             #region Actions
                                                                             DocumentRibbonBarMenuItems.Delete,
                                                                             DocumentRibbonBarMenuItems.MergePDF,
                                                                             DocumentRibbonBarMenuItems.SplitPDF,
                                                                             DocumentRibbonBarMenuItems.Split2,
                                                                             DocumentRibbonBarMenuItems.Split3,

                                                                             #endregion
                                                                             #region Outlook
                                                                             DocumentRibbonBarMenuItems.PlugginGroup,
                                                                             DocumentRibbonBarMenuItems.OpenDirectory,
                                                                             DocumentRibbonBarMenuItems.ReturnDirectory,

                                                                             #endregion
                                                                         };

        protected List<DocumentRibbonBarMenuItems> NoneModeExclude = new List<DocumentRibbonBarMenuItems>()
                                                                         {
                                                                             #region Rotate
                                                                             DocumentRibbonBarMenuItems.RotateGroup,
                                                                             DocumentRibbonBarMenuItems.RotateLeft,
                                                                             DocumentRibbonBarMenuItems.RotateRight,
                                                                             DocumentRibbonBarMenuItems.
                                                                                 SaveModifications,

                                                                             #endregion
                                                                             #region Actions
                                                                             DocumentRibbonBarMenuItems.ActionGroup,
                                                                             DocumentRibbonBarMenuItems.Delete,
                                                                             DocumentRibbonBarMenuItems.MergePDF,
                                                                             DocumentRibbonBarMenuItems.SplitPDF,
                                                                             DocumentRibbonBarMenuItems.Download,
                                                                             DocumentRibbonBarMenuItems.SendEmail,
                                                                             DocumentRibbonBarMenuItems.Print,
                                                                             DocumentRibbonBarMenuItems.DocumentPrint,
                                                                             DocumentRibbonBarMenuItems.AddDocument,
                                                                             DocumentRibbonBarMenuItems.Split2,
                                                                             DocumentRibbonBarMenuItems.Split3,
                                                                             DocumentRibbonBarMenuItems.SearchNext,
                                                                             DocumentRibbonBarMenuItems.SearchPrevious,

                                                                             #endregion
                                                                             #region Edit
                                                                             DocumentRibbonBarMenuItems.EditGroup,
                                                                             DocumentRibbonBarMenuItems.Cut,
                                                                             DocumentRibbonBarMenuItems.Copy,
                                                                             DocumentRibbonBarMenuItems.Paste,
                                                                             DocumentRibbonBarMenuItems.CheckIn,
                                                                             DocumentRibbonBarMenuItems.CheckOut,
                                                                             DocumentRibbonBarMenuItems.FolderLink,
                                                                             #endregion
                                                                             #region Workflow
                                                                             DocumentRibbonBarMenuItems.WorkflowGroup,
                                                                             DocumentRibbonBarMenuItems.Ventilate,

                                                                             #endregion
                                                                             #region Outlook
                                                                             DocumentRibbonBarMenuItems.PlugginGroup,
                                                                             DocumentRibbonBarMenuItems.OpenDirectory,
                                                                             DocumentRibbonBarMenuItems.ReturnDirectory,

                                                                             #endregion
                                                                         };

        #endregion

        #endregion

        #region User priviledges

        public bool CanDelete { get; set; }
        public bool CanTrash { get; set; }
        public bool CanModify { get; protected set; }
        public bool CanDownload { get; set; }
        public bool CanPrint { get; protected set; }
        public bool CanSendMail { get; protected set; }
        public bool CanImport { get; protected set; }

        protected List<DocumentRibbonBarMenuItems> m_oCanImport = new List<DocumentRibbonBarMenuItems>
                                                                      {
                                                                        #region Actions
                                                                            DocumentRibbonBarMenuItems.Scan,
                                                                            DocumentRibbonBarMenuItems.Import,
                                                                            DocumentRibbonBarMenuItems.AddDocument,
                                                                        #endregion
                                                                        #region Edit
                                                                            DocumentRibbonBarMenuItems.Paste,
                                                                            DocumentRibbonBarMenuItems.CheckOut,
                                                                            DocumentRibbonBarMenuItems.CheckIn,

                                                                        #endregion
                                                                    };
        protected List<DocumentRibbonBarMenuItems> m_oCanDelete = new List<DocumentRibbonBarMenuItems>
                                                                    {
                                                                        #region Actions
                                                                            DocumentRibbonBarMenuItems.Delete,
                                                                        #endregion
                                                                        #region Edit
                                                                            DocumentRibbonBarMenuItems.Cut,
                                                                        #endregion
                                                                    };
        protected List<DocumentRibbonBarMenuItems> m_oCanDownload = new List<DocumentRibbonBarMenuItems>
                                                                    {
                                                                        #region Actions
                                                                            DocumentRibbonBarMenuItems.Download,
                                                                        #endregion
                                                                    };
        protected List<DocumentRibbonBarMenuItems> m_oCanPrint = new List<DocumentRibbonBarMenuItems>
                                                                    {
                                                                        #region Actions
                                                                            DocumentRibbonBarMenuItems.Print,
                                                                            DocumentRibbonBarMenuItems.DocumentPrint,
                                                                        #endregion
                                                                    };
        protected List<DocumentRibbonBarMenuItems> m_oCanSendMail = new List<DocumentRibbonBarMenuItems>
                                                                    {
                                                                        #region Actions
                                                                            DocumentRibbonBarMenuItems.SendEmail,
                                                                        #endregion
                                                                    };

        #endregion

        /// <summary>
        /// Determines whether this instance can execute the specified button source.
        /// </summary>
        /// <param name="buttonSource">The button source.</param>
        /// <returns>
        /// 	<c>true</c> if this instance can execute the specified button source; otherwise, <c>false</c>.
        /// </returns>
        protected bool CanExecute(string buttonSource)
        {
            bool returnState = false;
            DocumentRibbonBarMenuItems l_oDocumentRibbonBarMenuItem;
            if (Enum.TryParse<DocumentRibbonBarMenuItems>(buttonSource, out l_oDocumentRibbonBarMenuItem))
            {
                returnState = IsAllowedInThisViewMode(l_oDocumentRibbonBarMenuItem, ViewMode);
                if (returnState)
                {
                    returnState = IsAllowedForThisDisplayMode(l_oDocumentRibbonBarMenuItem);
                }
            }
            return returnState;
        }

        /// <summary>
        /// Check if the button is allowed for the current view mode
        /// </summary>
        /// <param name="documentRibbonBarMenuItem">ribbon bar item</param>
        /// <param name="viewMode">current view mode</param>
        /// <returns>
        /// true or false
        /// </returns>
        protected bool IsAllowedInThisViewMode(DocumentRibbonBarMenuItems documentRibbonBarMenuItem, AppViewMode viewMode)
        {
            bool l_oReturnState = false;

            if ((documentRibbonBarMenuItem != DocumentRibbonBarMenuItems.Scan && documentRibbonBarMenuItem != DocumentRibbonBarMenuItems.Import)
                || ScanImportIsEnabled)
            {
                switch (ViewMode)
                {
                    case AppViewMode.Single:
                        l_oReturnState = SingleModeAvailables.Contains(documentRibbonBarMenuItem);
                        break;
                    case AppViewMode.Thumbnail:
                        l_oReturnState = ThumbnailModeAvailables.Contains(documentRibbonBarMenuItem);
                        break;
                    case AppViewMode.List:
                        l_oReturnState = ListModeAvailables.Contains(documentRibbonBarMenuItem);
                        break;
                }
            }

            return l_oReturnState;
        }

        /// <summary>
        /// Check if the button is allowed for the current display mode
        /// </summary>
        /// <param name="documentRibbonBarMenuItem">ribbon bar item</param>
        /// <returns>
        /// true or false
        /// </returns>
        protected bool IsAllowedForThisDisplayMode(DocumentRibbonBarMenuItems documentRibbonBarMenuItem)
        {
            bool returnState = true;
            switch (AppDisplayMode)
            {
                case AppDisplayMode.AddDocument:
                case AppDisplayMode.Import:
                    returnState = !ImportModeExclude.Contains(documentRibbonBarMenuItem);
                    break;

                case AppDisplayMode.ImportDirectory:
                    returnState = !ImportModeDirectoryExclude.Contains(documentRibbonBarMenuItem);
                    break;

                case AppDisplayMode.Search:

                    switch (ConsultationMode)
                    {
                        case ConsultationModeType.Workflow:

                            returnState = workflowModeEnum.Contains(documentRibbonBarMenuItem);

                            //Check priviledges
                            if (returnState)
                            {
                                returnState = IsUserAllowed(documentRibbonBarMenuItem);
                            }

                            if (returnState)
                            {
                                switch (documentRibbonBarMenuItem)
                                {
                                    case DocumentRibbonBarMenuItems.Paste:
                                        returnState = GlobalWebContext.CopyPasteManager.HasDocument;
                                        break;

                                    //Uncomment: 6.
                                    case DocumentRibbonBarMenuItems.Download:
                                        returnState = SelectedDocumentCount == 1;
                                        break;
                                }
                            }

                            break;
                        case ConsultationModeType.OldVersion:
                            returnState = OldVersionModeEnum.Contains(documentRibbonBarMenuItem);
                            break;
                        case ConsultationModeType.Trash:
                            returnState = TrashModeEnum.Contains(documentRibbonBarMenuItem);
                            if (returnState && documentRibbonBarMenuItem == DocumentRibbonBarMenuItems.Delete)
                            {
                                returnState = CanDelete;
                            }
                            break;
                        default:

                            if (documentRibbonBarMenuItem == DocumentRibbonBarMenuItems.Scan)
                            {
                                return false;
                            }

                            returnState = !SearchModeExclude.Contains(documentRibbonBarMenuItem);

                            //Check priviledges
                            if (returnState)
                            {
                                returnState = IsUserAllowed(documentRibbonBarMenuItem);
                            }

                            if (returnState)
                            {
                                switch (documentRibbonBarMenuItem)
                                {
                                    case DocumentRibbonBarMenuItems.Paste:
                                        returnState = GlobalWebContext.CopyPasteManager.HasDocument;
                                        break;

                                    case DocumentRibbonBarMenuItems.CheckIn:
                                    case DocumentRibbonBarMenuItems.CheckOut:
                                        returnState = IsVersioningEnabled;
                                        break;

                                    //Uncomment: 6.
                                    case DocumentRibbonBarMenuItems.Download:
                                        returnState = SelectedDocumentCount == 1;
                                        break;
                                }
                            }
                            break;
                    }
                    break;

                case AppDisplayMode.Flow:

                    switch (ConsultationMode)
                    {
                        case ConsultationModeType.Workflow:
                            returnState = workflowModeEnum.Contains(documentRibbonBarMenuItem);

                            //Check priviledges
                            if (returnState)
                            {
                                returnState = IsUserAllowed(documentRibbonBarMenuItem);
                            }

                            if (returnState)
                            {
                                switch (documentRibbonBarMenuItem)
                                {
                                    case DocumentRibbonBarMenuItems.Paste:
                                        returnState = GlobalWebContext.CopyPasteManager.HasDocument;
                                        break;
                                }
                            }

                            break;
                        case ConsultationModeType.OldVersion:
                            returnState = OldVersionModeEnum.Contains(documentRibbonBarMenuItem);
                            break;
                        case ConsultationModeType.Trash:
                            returnState = TrashModeEnum.Contains(documentRibbonBarMenuItem);
                            if (returnState && documentRibbonBarMenuItem == DocumentRibbonBarMenuItems.Delete)
                            {
                                returnState = CanDelete;
                            }
                            break;
                        default:
                            returnState = !FlowModeExclude.Contains(documentRibbonBarMenuItem);

                            //Check priviledges
                            if (returnState)
                            {
                                returnState = IsUserAllowed(documentRibbonBarMenuItem);
                            }

                            if (returnState)
                            {
                                switch (documentRibbonBarMenuItem)
                                {
                                    case DocumentRibbonBarMenuItems.Paste:
                                        returnState = GlobalWebContext.CopyPasteManager.HasDocument;
                                        break;
                                }
                            }
                            break;
                    }

                    break;

                case AppDisplayMode.SearchNone:
                case AppDisplayMode.None:
                    returnState = !NoneModeExclude.Contains(documentRibbonBarMenuItem);
                    switch (documentRibbonBarMenuItem)
                    {
                        case DocumentRibbonBarMenuItems.Paste:
                            returnState = GlobalWebContext.CopyPasteManager.HasDocument;
                            break;
                    }

                    break;
            }
            return returnState;
        }

        /// <summary>
        /// Check if the user is allowed for that button
        /// </summary>
        /// <param name="documentRibbonBarMenuItem">ribbon bar item</param>
        /// <returns>
        /// true or false
        /// </returns>
        protected bool IsUserAllowed(DocumentRibbonBarMenuItems documentRibbonBarMenuItem)
        {
            bool returnState = true;
            if (!CanImport && m_oCanImport.Contains(documentRibbonBarMenuItem))
            {
                returnState = false;
            }
            else if (!(CanDelete || CanTrash) && m_oCanDelete.Contains(documentRibbonBarMenuItem))
            {
                returnState = false;
            }
            else if (!CanDownload && m_oCanDownload.Contains(documentRibbonBarMenuItem))
            {
                returnState = false;
            }
            else if (!CanPrint && m_oCanPrint.Contains(documentRibbonBarMenuItem))
            {
                returnState = false;
            }
            else if (!CanSendMail && m_oCanSendMail.Contains(documentRibbonBarMenuItem))
            {
                returnState = false;
            }
            return returnState;
        }
    }
}
